package org.credo.net;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class SejdHttpPost {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HttpClient httpClient = new DefaultHttpClient();
		int httpStatusCode = 400;
		try {
			HttpPost httpPost = new HttpPost("http://www.baidu.com");
			// 一个名称/值对参数用作一个元素的HTTP消息。
			List<NameValuePair> nvps = new ArrayList<NameValuePair>();

//			Set<String> keySet = params.keySet();
//			for (String key : keySet) {
//				nvps.add(new BasicNameValuePair(key, params.get(key)));
//			}

			// 与该请求关联起来的实体。虽然是byte数组,但还是设置一下.
			httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));

			HttpResponse response = httpClient.execute(httpPost);
			httpStatusCode = response.getStatusLine().getStatusCode();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			httpClient.getConnectionManager().shutdown();
		}
		System.out.println("httpStatusCode:"+httpStatusCode);

	}

}
